package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    //查询总条数
    @Select("select count(*) from emp")
    Long findCount();


    //分页（limit） 查询数据列表
    @Select("select * from emp limit #{startIndex},#{pageSize}")
    List<Emp> findList(@Param("startIndex") Integer index,@Param("pageSize") Integer pageSize);

    //查询列表
    @Select("select * from emp")
    List<Emp> findList2();

    //分页 + 条件
    List<Emp> findList3(@Param("name") String name,@Param("gender") Integer gender,@Param("begin") LocalDate begin,
                        @Param("end") LocalDate end);


    //新增
    @Insert("insert into emp values(null.#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void save(Emp emp);

    //根据id查询
    @Select("select * from emp where id = #{id}")
    Emp findById(Integer id);

    //更新
    void update(Emp emp);

    //批量删除
    void deleteByIds(List<Integer> ids);


    //根据用户名查询
    @Select("select * from emp where username = #{username}")
    Emp findByUserName(String username);
}
